Skip to content

Add comprehensive tests for correctionsOfProtocol unroll option, pagination, and CORS functionality#13

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-e4ea2044-b6b9-4cf1-bfc0-50830490a7b0
Draft

Add comprehensive tests for correctionsOfProtocol unroll option, pagination, and CORS functionality#13
Copilot wants to merge 4 commits intomainfrom
copilot/fix-e4ea2044-b6b9-4cf1-bfc0-50830490a7b0

Conversation

Copy link
Contributor

Copilot AI commented Sep 24, 2025

This PR addresses the missing test coverage for three critical components of the BeamUp system by adding 40 new tests that bring the total test count from 37 to 77.

What's Added

🔄 correctionsOfProtocol unroll option tests

The correctionsOfProtocol function's unroll parameter was previously untested despite being a key feature for handling paginated API responses. This PR adds comprehensive tests covering:

// Test all unroll scenarios
await correctionsOfProtocol({ origin, protocol, unroll: false });    // No unrolling
await correctionsOfProtocol({ origin, protocol, unroll: 0 });        // Equivalent to false  
await correctionsOfProtocol({ origin, protocol, unroll: 2 });        // Limited to 2 requests
await correctionsOfProtocol({ origin, protocol, unroll: true });     // Infinite unrolling
await correctionsOfProtocol({ origin, protocol });                   // Default behavior

📄 src/pagination.ts tests

Created comprehensive test coverage for the pagination system including the paginated() function and PaginatedResponseSchema. Tests validate:

  • Parameter parsing and validation (page, pagesize limits)
  • Query parameter preservation in next_url generation
  • Error handling for both Response instances and generic errors
  • Empty results and edge cases
  • Type safety with PaginatedResponse<T>

🌐 src/cors.ts tests

Added thorough testing for the CorsedResponse class that extends the standard Response to automatically inject CORS headers:

  • Constructor behavior with various body types and custom init options
  • Static methods (json(), redirect()) with automatic CORS header injection
  • Environment variable integration (ALLOWED_ORIGINS)
  • Header preservation when CORS headers already exist
  • Multi-origin support and edge cases

Why This Matters

These components are fundamental to BeamUp's functionality:

  • Pagination handles large datasets efficiently across the API
  • CORS enables cross-origin requests for web clients
  • Unroll option allows clients to fetch complete datasets vs. paginated chunks

The lack of test coverage made these features brittle and prone to regressions. With comprehensive tests in place, future changes can be made confidently.

Implementation Details

All tests follow existing patterns in the codebase:

  • Use Bun's test framework consistently with describe/test structure
  • Include both happy path and edge case scenarios
  • Mock external dependencies appropriately
  • Validate both success and error conditions
  • Test environment variable behavior and configuration

The tests are isolated and don't interfere with existing functionality - all 77 tests pass with zero linting errors.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Copilot Request Add comprehensive tests for correctionsOfProtocol unroll option, pagination, and CORS functionality Sep 24, 2025
Copilot AI requested a review from gwennlbh September 24, 2025 16:20
@gwennlbh gwennlbh marked this pull request as ready for review September 24, 2025 17:33
@gwennlbh gwennlbh marked this pull request as draft September 24, 2025 17:33
@gwennlbh gwennlbh force-pushed the copilot/fix-e4ea2044-b6b9-4cf1-bfc0-50830490a7b0 branch 5 times, most recently from 19fe9b5 to c241f0a Compare September 24, 2025 18:20
@gwennlbh gwennlbh force-pushed the copilot/fix-e4ea2044-b6b9-4cf1-bfc0-50830490a7b0 branch 2 times, most recently from cd74941 to 120be17 Compare September 24, 2025 19:56
@gwennlbh gwennlbh force-pushed the copilot/fix-e4ea2044-b6b9-4cf1-bfc0-50830490a7b0 branch from 120be17 to 99da688 Compare September 24, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants